<?
function tpl_page_parent($tree)
{
	set_time_limit ( 5 );
	$ci = get_instance();
	$ci->load->library('tree');
	return $ci->tree->tree_to_options($tree, 'page_name', 'page_id');
}

function tpl_page_list($tree)
{
	foreach($tree as $index => $page)
	{
		echo '<li id="list_' . $page['page_id'] . '"><div class="green-gradient align-left thin">
						' . $page['page_name'] . '
						<a href="' . cms_url('pages/edit/'.$page['page_id']) . '" class="button compact float-right small-margin-right">Edit</a>
						<a href="' . cms_url('pages/delete/'.$page['page_id']) . '" class="button compact float-right small-margin-right">Delete</a> 
					</div>';
                	
               
				
		if(isset($page['children']) && !empty($page['children']))
		{
			echo '<ol>';
			tpl_page_list($page['children']);
			echo '</ol>';
		}
		echo  '</li>';
	}
}

function tpl_menu_list($tree)
{
	foreach($tree as $menu)
	{
		if(isset($menu['data'][$menu['type']]['name']))
		{
			$f = $menu['data'][$menu['type']]['name'];
		}
		$name = $menu['data']['names'][config_item('site_default_language')];
		echo '<li id="menu_' . $menu['id'] . '"><div class="green-gradient align-left thin">
						' . $name . '
						<span class="button-group float-right">
						<a href="' . cms_url('menus/edit/'.$menu['id']) . '" class="button compact icon-pencil"></a>
						<a href="' . cms_url('menus/delete/'.$menu['id']) . '" class="button compact icon-trash confirm"></a> 
						<a href="' . cms_url('menus/set_default/'.$menu['id']) . '" class="button compact red-gradient icon-star confirm"></a> 
						</span>						
						<small class="tag float-right small-margin-right small-margin-top">' . $menu['type'] . (isset($f) ? ': ' . $f : '') . '</small>
						' . ($menu['default'] == 1 ? '<small class="tag red-bg float-right small-margin-right small-margin-top">Default</small>' : '') .'
					</div>';
                	
               
				
		if(isset($menu['children']) && !empty($menu['children']))
		{
			echo '<ol>';
			tpl_menu_list($menu['children']);
			echo '</ol>';
		}
		echo  '</li>';
	}
}

?>